<!DOCTYPE html>
<html lang="zh-Hans">

<head>
    <meta charset="UTF-8" />
    <title>WasmOCC_Demo</title>
    <link rel="stylesheet" href="style.css" />
    <style>
        #loading {
            position: fixed;
            top: 50%;
            left: 50%;
            color: #202020;
            font-size: 20px;
            margin-top: -30px;
            margin-left: -40px;
        }
    </style>
</head>

<body id="body">
    <div id="file" >
       <input type="file" id="fileInput"  accept=".brep,.stp,.step,.igs,.iges" >
       <a href="/wasm-occ/occ_threejs/static/A22Z_EG1.step">step模型下载</a>
       <a href="/wasm-occ/occ_threejs/static/Ball.brep">brep模型下载</a>
       <a href="/wasm-occ/occ_threejs/static/111.igs">igs模型下载</a>
    </div>

    <p id="loading">loading......</p>
    <script type="text/javascript">
        var WasmOCC = {};
        var app = null;
        document.getElementById('file').style.display = 'none';
        fileInput.onchange = function () {
                    document.getElementById('loading').style.display = '';
                    if (fileInput.files.length == 0) { return; }
                    var aFile = fileInput.files[0];
                    var aReader = new FileReader();
                    aReader.onload = function () {
                        if(aReader.result)
                        {
                            var fileName=fileInput.files[0].name;
                            var fileExtension = fileName.substring(fileName.lastIndexOf('.') + 1);
                            fileExtension=fileExtension.toLowerCase();
                            if(fileExtension=="brep")
                            {
                                app.readBrep(aReader.result);
                            }
                            else if(fileExtension=="step"||fileExtension=="stp")
                            {
                                app.readStep(aReader.result);
                            }
                            else if(fileExtension=="iges"||fileExtension=="igs")
                            {
                                app.readIges(aReader.result);
                            }
                        }
                        document.getElementById('loading').style.display = 'none';
                    };
                    aReader.readAsText(aFile);        
                };
    </script>

    <script type="module">
        import { WasmOCC } from "./WasmOCC.js";
        import { occApp } from "./dist/index.js";
        WasmOCC.onRuntimeInitialized = function () {
               app= new occApp();
               document.getElementById('loading').style.display = 'none';
               document.getElementById('file').style.display = '';
        }
    </script>
</body>

</html>